//
//  ByDocumentaryDetailTitleCell.m
//  caipiao_ios
//
//  Created by mc on 2018/8/17.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByDocumentaryDetailTitleCell.h"



@implementation ByDocumentaryDetailTitleCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByDocumentaryDetailTitleCell";
    ByDocumentaryDetailTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
        
    }
    return self;
}


- (void)initViews{
    
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    UIView *backgroundView = [[UIView alloc] init];
    [self.contentView addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(6);
        make.right.equalTo(self.contentView).offset(-6);
        make.bottom.equalTo(self.contentView).offset(-10);
        make.top.equalTo(self.contentView).offset(2);
    }];
    backgroundView.backgroundColor = [UIColor whiteColor];
    backgroundView.layer.cornerRadius = 5;
    
    ByDocumentaryCellTitleView *titleView = [[ByDocumentaryCellTitleView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 10, 50)];
    [backgroundView addSubview:titleView];
    self.titleView = titleView;
    titleView.timeLabel.hidden = YES;
    titleView.recordLabel.hidden = YES;
    titleView.tapViewBlock = ^(){
        if (self.tapViewBlock) {
            self.tapViewBlock();
        }
    };
    
    UIImageView *iconView = [[UIImageView alloc] init];
    [backgroundView addSubview:iconView];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backgroundView).offset(13);
        make.right.equalTo(backgroundView).offset(-10);
        make.size.mas_equalTo(CGSizeMake(88, 23));
    }];
    iconView.image = [UIImage imageNamed:@"zhongjiang 1拷贝12"];
    self.iconView = iconView;
    
    UILabel *contentLabel = [[UILabel alloc] init];
    [backgroundView addSubview:contentLabel];
    contentLabel.numberOfLines = 0;
    contentLabel.text = _netModel.reason;
    CGFloat content_height = [_netModel.reason getRectOfStringWithSize:CGSizeMake(SCREEN_WIDTH - 34, 100) font:12].size.height + 20;
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleView.mas_bottom).offset(5);
        make.left.equalTo(backgroundView).offset(11);
        make.right.equalTo(backgroundView).offset(-11);
        make.height.mas_equalTo(@(content_height));
    }];
    contentLabel.font = FONT(12);
    contentLabel.textColor = BY_TEXT_COLOR;
    
    
    UIView *grayView = [[UIView alloc] init];
    [backgroundView addSubview:grayView];
    [grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(11);
        make.right.equalTo(backgroundView).offset(-11);
        make.bottom.equalTo(backgroundView).offset(-14);
        make.height.mas_equalTo(@75);
    }];
    grayView.backgroundColor = rgba(239, 239, 239, 1);
    CGFloat width = (SCREEN_WIDTH - 10 - 22) / 3.0;
    
    ByDocumentaryUserTitleValue *leftView = [[ByDocumentaryUserTitleValue alloc] initWithFrame:CGRectMake(0, 0, width, 75)];
    [grayView addSubview:leftView];
    leftView.titleLabel.textColor = [UIColor grayColor];
    leftView.titleLabel.text = @"5676元";
    leftView.valueLabel.text = @"认购金额";
    
    ByDocumentaryUserTitleValue *centerView = [[ByDocumentaryUserTitleValue alloc] initWithFrame:CGRectMake(width, 0, width, 75)];
    [grayView addSubview:centerView];
    centerView.titleLabel.textColor = [UIColor grayColor];
    centerView.titleLabel.text = @"未中奖";
    centerView.valueLabel.text = @"方案状态";
    
    ByDocumentaryUserTitleValue *rightView = [[ByDocumentaryUserTitleValue alloc] initWithFrame:CGRectMake(width * 2, 0, width, 75)];
    [grayView addSubview:rightView];
    rightView.titleLabel.textColor = [UIColor grayColor];
    rightView.titleLabel.text = @"0元";
    rightView.valueLabel.text = @"赚取佣金";
    
    self.leftView = leftView;
    self.centerView = centerView;
    self.rightView = rightView;
    
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    [self initViews];
    
     [self.titleView.iconView sd_setImageWithURL:[NSURL URLWithString:netModel.head_pic] placeholderImage:HEAD_ICOM_IMAGE];
     self.titleView.nickLabel.text = netModel.nickname;
     self.titleView.timeLabel.text = [NSString stringWithFormat:@"截止时间:%@",[NSDate getDateForStringFotmatWithTimeInterval:netModel.end_time.integerValue formatter:@"MM-dd HH:mm"]];
    
    self.leftView.titleLabel.text = [NSString stringWithFormat:@"%@元", netModel.total_amount];
    self.rightView.titleLabel.text = [NSString stringWithFormat:@"%@元", netModel.commission];
    if (netModel.is_result.integerValue == 0) {
        
        self.centerView.titleLabel.text = @"未开奖";
        self.iconView.image = [UIImage imageNamed:@"dengdaikaijian等待开奖"];
        
    }else{
        if (netModel.lottery_result.integerValue == 0) {
            self.centerView.titleLabel.text = @"未中奖";
            self.iconView.image = [UIImage imageNamed:@"zaijiezaili 拷贝未中奖"];
            
        }else{
            self.centerView.titleLabel.text = @"已中奖";
            self.iconView.image = [UIImage imageNamed:@"zhongjiang 1拷贝12"];
        }
    }
    
}

@end
